package com.tree.service.impl;

import com.tree.dao.UserDao;
import com.tree.entity.User;
import com.tree.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Override
    public int insert(User user) {
        //判断有无此用户
        User tmp = userDao.query(user.getUserNum());
        if (tmp == null || tmp.getUserNum() == null)
            return userDao.insert(user);
        return -1;
    }

    @Override
    public boolean query(String userNum) {
        //判断账号是否存在
        User user = userDao.query(userNum);
        if (user != null && user.getUserNum() != null)
            return true;
        return false;
    }

    @Override
    public boolean queryAll(User user) {
        //判断账号密码是否正确
        User users = userDao.queryAll(user);
        if (users != null && users.getUserNum() != null && users.getUserPsw() != null)
            return true;
        return false;
    }
}
